//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.beadwallet.alarm.util;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.config.RequestConfig.Builder;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HttpUtil {
    private static PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager();
    private static RequestConfig requestConfig;
    private static final int MAX_TIMEOUT = 60000;
    protected static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);

    public HttpUtil() {
    }

    public static String doGet(String url) {
        return doGet(url, new HashMap());
    }

    public static String doGet(String url, Map<String, Object> params) {
        StringBuffer param = new StringBuffer();
        int i = 0;

        for(Iterator var5 = params.keySet().iterator(); var5.hasNext(); ++i) {
            String key = (String)var5.next();
            if(i == 0) {
                param.append("?");
            } else {
                param.append("&");
            }

            param.append(key).append("=").append(params.get(key));
        }

        String apiUrl = url + param;
        String result = null;
        DefaultHttpClient httpclient = new DefaultHttpClient();

        try {
            HttpGet httpPost = new HttpGet(apiUrl);
            HttpResponse response = httpclient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            result = EntityUtils.toString(entity, "UTF-8");
        } catch (IOException var10) {
            logger.error(apiUrl, var10);
        }

        logger.info("url:" + apiUrl + "-----result:" + result);
        return result;
    }

    public static String doPost(String apiUrl) {
        return doPost(apiUrl, (Map)(new HashMap()));
    }

    public static String doPost(String apiUrl, Map<String, Object> params) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        String httpStr = null;
        HttpPost httpPost = new HttpPost(apiUrl);
        CloseableHttpResponse response = null;

        try {
            httpPost.setConfig(requestConfig);
            List<NameValuePair> pairList = new ArrayList(params.size());
            Iterator var7 = params.entrySet().iterator();

            while(var7.hasNext()) {
                Entry<String, Object> entry = (Entry)var7.next();
                NameValuePair pair = new BasicNameValuePair((String)entry.getKey(), entry.getValue().toString());
                pairList.add(pair);
            }

            logger.info("【post parameters】:{}", pairList);
            httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
            response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            httpStr = EntityUtils.toString(entity, "UTF-8");
        } catch (IOException var18) {
            logger.error(httpPost.toString(), var18);
        } finally {
            if(response != null) {
                try {
                    EntityUtils.consume(response.getEntity());
                } catch (IOException var17) {
                    logger.error(apiUrl, var17);
                }
            }

        }

        logger.debug("url:" + apiUrl + "-----result:" + httpStr);
        return httpStr;
    }

    public static String doPost(String apiUrl, String param, Header header) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        String httpStr = null;
        HttpPost httpPost = new HttpPost(apiUrl);
        CloseableHttpResponse response = null;

        try {
            if(null != header) {
                httpPost.setHeader(header);
            }

            httpPost.setConfig(requestConfig);
            StringEntity stringEntity = new StringEntity(param, "UTF-8");
            stringEntity.setContentEncoding("UTF-8");
            httpPost.setEntity(stringEntity);
            response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            httpStr = EntityUtils.toString(entity, "UTF-8");
        } catch (IOException var17) {
            logger.error(httpPost.toString(), var17);
        } finally {
            if(response != null) {
                try {
                    EntityUtils.consume(response.getEntity());
                } catch (IOException var16) {
                    logger.error(httpPost.toString(), var16);
                }
            }

        }

        logger.info("url:" + apiUrl + "-----result:" + httpStr);
        return httpStr;
    }

    public static String doPost(String apiUrl, String param) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        String httpStr = null;
        HttpPost httpPost = new HttpPost(apiUrl);
        CloseableHttpResponse response = null;

        try {
            httpPost.setConfig(requestConfig);
            StringEntity stringEntity = new StringEntity(param, "UTF-8");
            stringEntity.setContentEncoding("UTF-8");
            httpPost.setEntity(stringEntity);
            response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            httpStr = EntityUtils.toString(entity, "UTF-8");
        } catch (IOException var16) {
            logger.error(httpPost.toString(), var16);
        } finally {
            if(response != null) {
                try {
                    EntityUtils.consume(response.getEntity());
                } catch (IOException var15) {
                    logger.error(httpPost.toString(), var15);
                }
            }

        }

        logger.info("url:" + apiUrl + "-----result:" + httpStr);
        return httpStr;
    }
}
